<?php
/**
 *description:仓库管理
 *author:李飞@天众科技
 *time:2016/12/27
 */

namespace Admin\Controller;
use Think\Controller;
class DepotController extends CommonController {
	
    public function index(){
		$this->redirect('erp');
    }
	public function erp(){
		$this->display();
    }
	public function books(){
		$erplist=erplist();
		$this->assign('erplist',$erplist);
		$this->display();
    }
	// 账册详情
	public function booksCateInfo(){
		$id=I('id','','trim');
		$detail=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'))->field('code')->find($id);//详情
		$detail['manua_id']=$detail['code'];
		$countrylist=countrylist();
		$coinlist=coinlist();
		$unitlist=unitlist();
		$manua_idlist=manua_idlist();//账册列表
		$this->assign('detail',$detail);//详情
		$this->assign('manua_idlist',$manua_idlist);//产销国列表
		$this->assign('countrylist',$countrylist);//产销国列表
		$this->assign('coinlist',$coinlist);//币制列表
		$this->assign('unitlist',$unitlist);//单位列表
		$this->display();
	}
	//添加多到货商品
	public function adddgoods(){
		$m=M('Books',C('DB_PRS'),C('DB_DEPOT'));
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$aop=M('ArrivalOrderPlan',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$goods_id=$param['goods_id'];
		$order_id=$param['order_id'];
		$ao_info=$ao->where(array('plan_id'=>$order_id))->find();
		
		$m_info=$m->where(array('id'=>$goods_id))->find();
		$goods_no=$m_info["goods_no"];
		$duplicate=$ao->where(array('plan_id'=>$order_id,'goods_no'=>$goods_no))->find();
		if(!empty($duplicate)){
			alert_json(0,'该商品已经存在！');
		}
		$aop_info=$aop->where(array('id'=>$order_id))->find();
		$data_info_clild=array();
		$data_info_clild['order_no']		=$aop_info['order_no'];
		$data_info_clild['batch_no']		=$aop_info['batch_no'];
		$data_info_clild['plan_id']			=$order_id;
		$data_info_clild['old_goods_id']	=$m_info['id'];
		$data_info_clild['old_purchasing_no']=$ao_info['old_purchasing_no'];
		$data_info_clild['manual_id']		=$m_info['manua_id'];
		$data_info_clild['source_no']		=$m_info['source_no'];
		if(empty($m_info['item_no'])){
			alert_json(0,'没有项号信息，请先完善信息再添加');
		}
		if(is_null($m_info['item_type'])){
			alert_json(0,'没有料件性质信息，请先完善信息再添加');
		}
		if(empty($m_info['hs_code'])){
			alert_json(0,'没有hs_code信息，请先完善信息再添加');
		}
		$data_info_clild['item_no']			=$m_info['item_no'];
		$data_info_clild['item_type']		=$m_info['item_type'];
		$data_info_clild['goods_no']		=$m_info['goods_no'];
		$data_info_clild['hscode']			=$m_info['hs_code'];
		$data_info_clild['goods_name']		=$m_info['goods_name'];
		$data_info_clild['declare_amount']	=0;
		$data_info_clild['total_price']		=0;
		$data_info_clild['price']			=0;
		$data_info_clild['declare_unit']	=$m_info['unit1'];
		$data_info_clild['unit1']			=$m_info['unit1'];
		$data_info_clild['status']			=1;
		$data_info_clild['country_code']	=$m_info['source'];
		$data_info_clild['currency']		=$m_info['current_type'];
		$data_info_clild['bar_code']		=$m_info['bar_code'];
		$data_info_clild['add_time']		=time();
		$res=$ao->add($data_info_clild);
		// echo $ao->getlastsql();
		// die;
		if($res){
			alert_json(1,'添加成功');
		}else{
			alert_json(1,'添加失败');
		}
	}
	//部门管理
	public function section(){
		$this->display();
    }
	//部门人员表
	public function personnel(){
		$sectionlist=sectionlist();
		$this->assign('sectionlist',$sectionlist);
		$this->display();
    }
	//往来单位
	public function contactsCompany(){
		$this->display();
    }	
	//出库类型
	public function outbound_cate(){
		$this->display();
    }
	//部门列表数据
	public function get_section(){
        $ck=A('CheckInput');
		//参数验证
        $no=$ck->in('部门编号','no','ennumstr','',0,0);
        $name=$ck->in('部门名称','name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($no)?$map['no']=array('like','%'.$no.'%'):'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		
		//获取数据
        $data=getTable('Section',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }	
	//部门人员列表
	public function get_personnel(){
        $ck=A('CheckInput');
		//参数验证
        $no=$ck->in('员工编号','no','ennumstr','',0,0);
        $name=$ck->in('员工姓名','name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($no)?$map['no']=array('like','%'.$no.'%'):'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		
		//获取数据
        $data=getTable('Personnel',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//往来单位列表
	public function get_contactsCompany(){
        $ck=A('CheckInput');
		//参数验证
        $no=$ck->in('公司编码','no','ennumstr','',0,0);
        $name=$ck->in('公司名称','name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($no)?$map['no']=array('like','%'.$no.'%'):'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		
		//获取数据
        $data=getTable('ContactsCompany',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//出库类型列表
	public function get_outboundcate(){
        $ck=A('CheckInput');
		//参数验证
        $no=$ck->in('公司编码','no','ennumstr','',0,0);
        $name=$ck->in('公司名称','name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($no)?$map['no']=array('like','%'.$no.'%'):'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		
		//获取数据
        $data=getTable('OutboundCate',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//账册分类详情
	public function get_booksInfoCate(){
		
        $ck=A('CheckInput');
		//参数验证
        $goods_no=$ck->in('商品编号','goods_no','ennumstr','',0,0);
		$source_no=trim(I('source_no'));
        $goods_name=$ck->in('商品名称','goods_name','cnennumstr','',0,0);
		$manua_id=$ck->in('账册编号','manua_id','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
		$sort=I("sort");
		if(empty($sort)){
			$sort="status,id";
		}else{
			$sort="status,".$sort;
		}
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		$cate_id=I('cate_id','','trim');
		if(!empty($cate_id)){
			$detail=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'))->field('code')->find($cate_id);//详情
			$map['manua_id']=$detail['code'];
		}
		
		!empty($source_no)?$map['source_no']=array('like',"%$source_no%"):'';
		!empty($goods_no)?$map['goods_no']=array('like','%'.$goods_no.'%'):'';
        !empty($goods_name)?$map['goods_name']=array('like','%'.$goods_name.'%'):'';
		!empty($manua_id)?$map['manua_id']=$manua_id:'';
		
		//获取数据
        $data=getTable('Books',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//账册分类列表
	public function get_booksCate(){
        $ck=A('CheckInput');
		//参数验证
		$erpId=I('erpId');
        $code=$ck->in('账册编号','code','ennumstr','',0,0);
		$cate=$ck->in('账册类别','cate','ennumstr','',0,0);
        $name=$ck->in('账册名称','name','cnennumstr','',0,0);
		$erp_name=$ck->in('企业名称','erp_name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($code)?$map['code']=array('like','%'.$code.'%'):'';
		!empty($cate)?$map['cate']=$cate:'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		if(!empty($erpId)){
			$list_erp=M('Erp',C('DB_PRS'),C('DB_DEPOT'))->find($erpId);
			$map['erp_code']=$list_erp['code'];
		}
		
		if(!empty($erp_name)){
			$maps['name']=array('like','%'.$erp_name.'%');
			$list_erp=M('Erp',C('DB_PRS'),C('DB_DEPOT'))->where($maps)->select();
			
			foreach($list_erp as $k=>$v){
				$arr[$k]=$v['code'];
			}
			$map['erp_code']=array('in',$arr);
		}
		
		//获取数据
        $data=getTable('BooksCate',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//erp企业列表
	public function get_erp(){
        $ck=A('CheckInput');
		//参数验证
        $code=$ck->in('企业编码','code','ennumstr','',0,0);        
        $name=$ck->in('企业名称','name','cnennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
        //排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
        //搜索条件
        $map=array();
		!empty($code)?$map['code']=array('like','%'.$code.'%'):'';
        !empty($name)?$map['name']=array('like','%'.$name.'%'):'';
		//获取数据
        $data=getTable('Erp',$map,$page,$rows,$sort,$order,$status);
        $this->ajaxReturn($data);
    }
	//添加部门
    public function sectionAdd(){
		$m=M('Section',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['no']=I('no');
		$data['name']=I('name');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['no']=I('no');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='部门编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
		
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//添加员工
    public function personnelAdd(){

		$m=M('Personnel',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['no']=I('no');
		$data['name']=I('name');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['no']=I('no');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='员工编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//添加往来单位
    public function contactsCompanyAdd(){

		$m=M('ContactsCompany',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['no']=I('no');
		$data['name']=I('name');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['no']=I('no');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='单位编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//添加出库类型
    public function OutboundcateAdd(){

		$m=M('OutboundCate',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['no']=I('no');
		$data['name']=I('name');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['no']=I('no');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='单位编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	
	//添加账册详情
    public function booksInfoCateAdd(){

		$m=M('Books',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['manua_id']=I('manua_id');
		$data['goods_no']=I('goods_no');
		$data['goods_name']=I('goods_name');
		$data['goods_spec']=I('goods_spec');
		$data['unit1']=I('unit1');
		$data['unit2']=I('unit2');
		$data['item_no']=I('item_no');
		$data['item_type']=I('item_type');
		$data['hs_code']=I('hs_code');
		$data['current_type']=I('current_type');
		$data['source_no']=I('source_no');
		$data['source']=I('source');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['goods_no']=I('goods_no');
		$map['manua_id']=I('manua_id');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='商品编码已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//添加账册分类
    public function booksCateAdd(){
		$m=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput');  
		$data['cate']=$ck->in('账册分类','cate','ennumstr','',0,0);
        $data['name']=$ck->in('账册名称','name','cnennumstr','',0,0);
		$data['code']=$ck->in('账册编号','code','ennumstr','',0,0);
		$data['merchant_code']=$ck->in('商家编码','merchant_code','cnennumstr','',0,0);
		
		$emsfee_rate=I('emsfee_rate','','trim');
		if($emsfee_rate<1){
			$return['message']='快递费率必须大于1!';
			$return['status']=false; 
			$this->ajaxReturn($return);
		}
		$data['emsfee_rate']=$emsfee_rate;
		
		$data['erp_code']=$ck->in('ERP企业编码','erp_code','ennumstr','',0,0);
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['code']=I('code');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='账册编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//添加企业信息
    public function erpAdd(){
		$m=M('Erp',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput');  
        $data['code']=$ck->in('企业编码','code','ennumstr','',1,20);  
        $data['name']=$ck->in('企业名称','name','cnennumstr','',1,20);
		$data['url']=I('url','','trim');
		$data['add_time']=time();
		$data['update_time']=time();
		//重复判断
		$map['code']=I('code');
		$duplicate=$m->where($map)->find();
		if($duplicate){
			$return['message']='企业编码已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
        $insertId=$m->add($data);
		// echo $m->getlastsql();
		// die;
        if(!$insertId){
            $return['message']='添加企业失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加企业成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新部门信息
    public function sectionSave(){
		$m=M('Section',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['name']=I('name');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新员工信息
    public function personnelSave(){
		
		$m=M('Personnel',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['name']=I('name');
		$data['section_no']=I('section_no');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新往来单位
    public function contactsCompanySave(){
		$m=M('ContactsCompany',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['name']=I('name');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
		
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新出库类型
    public function OutboundcateSave(){
		$m=M('OutboundCate',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['name']=I('name');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
		
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新账册信息
    public function booksInfoCateSave(){
		$m=M('Books',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['goods_no']=I('goods_no');
		$data['goods_name']=I('goods_name');
		$data['goods_spec']=I('goods_spec');
		$data['unit1']=I('unit1');
		$data['unit2']=I('unit2');
		$data['item_no']=I('item_no');
		$data['item_type']=I('item_type');
		$data['hs_code']=I('hs_code');
		$data['current_type']=I('current_type');
		$data['source']=I('source');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
		//重复判断
		$maps['goods_no']=I('goods_no');
		$maps['manua_id']=I('manua_id');
		$maps['id']=array('neq',$map['id']);
		$duplicate=$m->where($maps)->find();
		// echo $m->getlastsql();
		if($duplicate){
			$return['message']='商品编号已经存在';
            $return['status']=false;
            $this->ajaxReturn($return);
		}
		
        $result=$m->where($map)->save($data);
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新账册分类信息
    public function booksCateSave(){
		$m=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['cate']=$ck->in('账册分类','cate','ennumstr','',0,0);
        $data['name']=$ck->in('账册名称','name','cnennumstr','',0,0);
		$data['merchant_code']=$ck->in('商家编码','merchant_code','cnennumstr','',0,0);
		$data['erp_code']=$ck->in('ERP企业编码','erp_code','ennumstr','',0,0);
		$emsfee_rate=I('emsfee_rate','','trim');
		if($emsfee_rate<1){
			$return['message']='快递费率必须大于1!';
			$return['status']=false; 
			$this->ajaxReturn($return);
		}
		$data['emsfee_rate']=$emsfee_rate;
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
    //更新企业信息
    public function erpSave(){
		$m=M('Erp',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
        $data['name']=$ck->in('企业名称','name','cnennumstr','',1,20);
		$data['url']=I('url','','trim');
		$data['update_time']=time();
        $map['id']=$ck->in('erp企业id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
        if(false===$result){
            $return['message']='更新企业信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新企业信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	/**
     * ajax检查erp企业编码是否存在
     * @author 李飞
     */
    public function checkErpCode(){
		$return=tableCheckInputFunc('Erp','code','企业编码','val','ennumstr','',2,10);
        $this->ajaxReturn($return);        
    }
	//审核erp企业
    public function get_examine(){
		$return=tableExamine('Erp');
        $this->ajaxReturn($return);
    }
	//删除
    public function erpDel(){
		$return=tableDel('Erp');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function erpClear(){
		$return=tableClear('Erp');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function erpUndo(){
		$return=tableUndo('Erp');
        $this->ajaxReturn($return);
    }
	/**
     * ajax检查账册编号是否存在
     * @author 李飞
     */
    public function checkBooksCateCode(){
		$return=tableCheckInputFunc('BooksCate','code','账册名称编号','val','ennumstr','',2,10);
        $this->ajaxReturn($return);        
    }
	//审核
    public function examineBooksCate(){
		//审核判断详情为空或值为0
		// $m=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
		// $n=M('Books',C('DB_PRS'),C('DB_DEPOT'));
		// $id=I('id');
		// $arr=explode(',',$id);
		// foreach($arr as $k=>$v){
			// $booksInfo=$m->where(array('id'=>$v))->find();
			// $map['manua_id']=$booksInfo['code'];
			// $info=$n->where($map)->select();
			// if(!$info){
				// $return['message']='没有详情信息，请添加详情!';
				// $return['status']=false; 
				// $this->ajaxReturn($return);
				// die;
			// }else{
				// foreach($info as $key=>$value){
					// if($value['status']==0){
						// $return['message']='详情信息未审核，请先审核详情!';
						// $return['status']=false; 
						// $this->ajaxReturn($return);
						// die;
					// }
				// }
			// }
		// }
		$return=tableExamine('BooksCate');
        $this->ajaxReturn($return);
    }
	//删除
    public function booksCateDel(){
		$return=tableDel('BooksCate');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function booksCateClear(){
		$return=tableClear('BooksCate');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function booksCateUndo(){
		$return=tableUndo('BooksCate');
        $this->ajaxReturn($return);
    }

	//////////////////////////////////////////////////////
	//审核账册详情
    public function examineBooksInfoCate(){
		$return=tableExamine('Books');
        $this->ajaxReturn($return);
    }
	//删除
    public function booksInfoCateDel(){
		$return=tableDel('Books');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function booksInfoCateClear(){
		$return=tableClear('Books');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function booksInfoCateUndo(){
		$return=tableUndo('Books');
        $this->ajaxReturn($return);
    }
	//////////////////////////////////////////////////////
	//审核新增部门
    public function examineSection(){
		$return=tableExamine('Section');
        $this->ajaxReturn($return);
    }
	//删除
    public function sectionDel(){
		$return=tableDel('Section');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function sectionClear(){
		$return=tableClear('Section');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function sectionUndo(){
		$return=tableUndo('Section');
        $this->ajaxReturn($return);
    }
	//////////////////////////////////////////////////////
	//审核新增员工
    public function examinePersonnel(){
		$return=tableExamine('Personnel');
        $this->ajaxReturn($return);
    }
	//删除
    public function personnelDel(){
		$return=tableDel('Personnel');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function personnelClear(){
		$return=tableClear('Personnel');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function personnelUndo(){
		$return=tableUndo('Personnel');
        $this->ajaxReturn($return);
    }
	//////////////////////////////////////////////////////
	//审核新增往来单位
    public function examineContactsCompany(){
		$return=tableExamine('ContactsCompany');
        $this->ajaxReturn($return);
    }
	//删除
    public function contactsCompanyDel(){
		$return=tableDel('ContactsCompany');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function contactsCompanyClear(){
		$return=tableClear('ContactsCompany');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function contactsCompanyUndo(){
		$return=tableUndo('ContactsCompany');
        $this->ajaxReturn($return);
    }
	//////////////////////////////////////////////////////
	//审核出库类型
    public function examineOutboundcate(){
		$return=tableExamine('OutboundCate');
        $this->ajaxReturn($return);
    }
	//删除
    public function OutboundcateDel(){
		$return=tableDel('OutboundCate');
        $this->ajaxReturn($return);
    }
	//清空回收站
    public function OutboundcateClear(){
		$return=tableClear('OutboundCate');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据
    public function OutboundcateUndo(){
		$return=tableUndo('OutboundCate');
        $this->ajaxReturn($return);
    }
	//其它入库详情数据添加
    public function otherInboundAddUrl(){
		$m=M('OtherInboundInfo',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('OtherInbound',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput');  
        $id=$ck->in('id','id','string','',1,0);
		$otherInboundCate=$ck->in('其它入库单id','otherInboundCate','intval','',1,0);
        if(empty($id)) exit;//为空
		$data_n['add_goods']=1;
		$data_m['order_id']=$otherInboundCate;
		$arr=explode(',', $id);
		$i=0;//新增
		$j=0;//失败
		$k=0;//重复
		foreach($arr as $key=>$v){
			$data_m['books_id']=$v;
			$detail=$m->where($data_m)->find();
			if($detail){
				$k++;
			}else{
				$result=$m->add($data_m);
				// echo $m->getlastsql();
				// die;
				if($result){
					$i++;
				}else{
					$j++;
				}
			}
		}
		
		if($i){
			$n->where(array('id'=>$otherInboundCate))->save($data_n);
			$message=$i.'个添加成功!';
		}
		if($j){
			$message=$j.'个添加失败!';
		}
		if($k){
			$message=$k.'个重复!';
		}
		$return['message']=$message;
        $return['status']=true;
        $this->ajaxReturn($return);
	}
}